
* Census data
do "code_Stata/5a_TableB1_A.do"
local n = _N
set obs `=`n'+1'
replace year = 1971 if year == .
sort year
gen mergeyear = year
replace mergeyear = 1975 if year == 1971
tempfile censos 
save `censos'

* Household surveys
do "code_Stata/5b_TableB1_B.do"
gen mergeyear = year
renvars year-Missing, postfix(_eh)

* Merge
merge 1:1 mergeyear using `censos'
drop _m

* organize
sort year
order year-Licenciado
drop mergeyear


	
			**	**	**	**	**	**	**	**	**	**	**	**	**
			**	**	**	**	**	**	**	**	**	**	**	**	**
			**	**	**	**	**	**	**	**	**	**	**	**	**

*-------------------------------------------------------------------------------
* format table 
*-------------------------------------------------------------------------------

* rounding
foreach var of varlist Menos* Prim* Bach* Lic* {
	replace `var' = round(`var'*100)
	}
tostring *, replace force


* format
foreach var of varlist Menos* Prim* Bach* Lic* {
	replace `var' = `var' + "\%" if `var' ~= "."
	replace `var' = "" if `var' == "."
	}
replace year_eh = "" if year_eh == "."	
	

* turn 1961 gray
foreach var of varlist year-Licenciado {
	replace `var' = "\textcolor{gray}{" + `var' + "}" if regexm(year, "1961")	
	}
	
* Notes
replace year = subinstr(year, "1961", "1961$^1$", .)
replace year = "1971$^2$" if year == "1971"


* outsheet
gen latex_table1 = year
foreach var of varlist MenosDePrimaria-Licenciado_eh {
	replace latex_table1 = latex_table1 + " & " + `var'
	}
replace latex_table1 = latex_table1 + " \\[0.35em]"
outsheet latex_table1 using "tables/TableB1.tex", noquote nonames replace


* End
